package team.kirohuji.repository.jpa.tidings;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import team.kirohuji.domain.tidings.Notify;
import team.kirohuji.domain.tidings.Subscription;

@Repository
public interface SubscriptionRepository extends JpaRepository<Subscription,Integer>{
	@Query(value="select * from subscription where user_id=?1",nativeQuery=true)
	public List<Subscription> findAllByUserId(Integer userId);
	
	@Query(value="delete from subscription where target_id = ?1 and target_type = ?2 and user_id = ?3",nativeQuery=true)
	public Subscription deleteByNotifyParam(Integer targetId, String targetType, Integer userId);
	
	@Query(value="select user_id from subscription where target_id = ?1 and target_type = ?2 and action = ?3",nativeQuery=true)
	public List<Integer> findUserByNotifyParam(Integer targetId, String targetType,String action);
}
